package com.lagou.session;

import com.lagou.config.XmlConfigBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @ClassName: SqlSessionFactoryBuilder
 * @Auther: Jerry
 * @Date: 2020/6/19 23:39
 * @Desctiption: TODO
 * @Version: 1.0
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws DocumentException, PropertyVetoException {
        // 1. 使用dom4j解析内容封装到configuration中
        Configuration configuration = new XmlConfigBuilder().parse(in);

        // 2. 创建sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }
}
